//This file is included both by post_list.html and post.html
//these are to be used with conn.sendData(), for debugging.
const ENTER = '\x0D';
const LEFT = '\x1B[D';
const RIGHT = '\x1B[C';
const PAGEUP = '\x1B[5~';
const PAGEDOWN = '\x1B[6~';
const END = '\x1B[4~';
const HOME = '\x1B[1~';

var tabulator, kb, sf, bbsProtocolHandler, conn;
var SIOC, DCTERMS, BBS, RDFS, CONTENT;
var Cc, Ci, Cr;
var isBBS; //is this a BBS post list?
//string utility (Python)
String.prototype.startswith = function startswith(aOther){
  return this.substr(0, aOther.length) === aOther;
}
function initializeGlobals(){
  //in case of a HTTP blog/forum tabulator is passed from passingKb
  if (typeof tabulator === "undefined"){
    Cc = Components.classes;
    Ci = Components.interfaces;
    Cr = Components.results;
    tabulator = Cc["@dig.csail.mit.edu/tabulator;1"].getService().
                wrappedJSObject;
  }

  kb = tabulator.kb;
  sf = tabulator.sf;
  SIOC = tabulator.ns.sioc; //property namespace
  DCTERMS = tabulator.ns.dcterms; //property namespace
  BBS = tabulator.ns.bbs; //property namespace
  RDFS = tabulator.ns.rdfs; //property namespace
  FOAF = tabulator.ns.foaf;
  CONTENT = function CONTENT(aTerm) 
    kb.sym("http://purl.org/rss/1.0/modules/content/" + aTerm);
  bbsProtocolHandler = 
      Components.classes["@mozilla.org/network/protocol;1?name=bbs"].
      getService().wrappedJSObject;

  if (document.location.protocol === "bbs:") {
    isBBS = true;
    /*
    bbsProtocolHandler = 
      Components.classes["@mozilla.org/network/protocol;1?name=bbs"].
      getService().wrappedJSObject;
    */
    conn = bbsProtocolHandler.
           mRootConnectionDict["bbs://" + document.location.host];
  } else {    
    isBBS = false;
  }
}

window.addEventListener("DOMContentLoaded", initializeGlobals, false);
//for some reason "load" event doesn't always fire so "DOMContentLoaded" is
//used instead. passingGlobals (defined in chromeWindowStartupOverride.js) fires
//quicker because it is registered on the caputre phase, while
//initilaizeGlobals is registered on the bubbling phase. See 
//<http://www.w3.org/TR/DOM-Level-3-Events/#dom-event-architecture> for a
//nice picture //@ understand why "load" doesn't get fireds
